package org.example.medical.utils;

public class ApiResult<T> {
    private int code;
    private String message;
    private T data;

    // 成功的构造方法
    public ApiResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    // 失败的构造方法
    public ApiResult(int code, String message) {
        this.code = code;
        this.message = message;
    }

    // 获取器和设置器
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    // 静态方法，用于快速创建成功响应
    public static <T> ApiResult<T> success(T data) {
        return new ApiResult<>(200, "Success", data);
    }

    public static <T> ApiResult<T> success(T data, String message) {
        return new ApiResult<>(200, message, data);
    }

    // 静态方法，用于快速创建失败响应
    public static <T> ApiResult<T> failure(int code, String message) {
        return new ApiResult<>(code, message);
    }
}